package com.bw.unit3.view.adapter

import android.content.Context
import android.widget.CheckBox
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bw.unit3.R
import com.bw.unit3.bean.CartBean
import com.zhy.adapter.recyclerview.CommonAdapter
import com.zhy.adapter.recyclerview.base.ViewHolder
import org.greenrobot.eventbus.EventBus

/**
 *
 * @ClassName: HomeGoodsAdapter
 * @Description: 首页，商品列表适配器
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/19 5:18 PM
 * @Version: 1.0
 */
class CartAdapter(
    context: Context?, itemLayoutId: Int, mData: MutableList<CartBean>
) : CommonAdapter<CartBean>(context, itemLayoutId, mData) {
    override fun convert(holder: ViewHolder?, t: CartBean?, position: Int) {
        holder?.setText(R.id.tv_goods, t?.goods_desc)
        holder?.setText(R.id.item_tv_price, "¥ ${t?.goods_default_price}")

        val checkBox = holder?.getView<CheckBox>(R.id.item_check)
        checkBox!!.isChecked = t!!.isCheck
        checkBox!!.setOnClickListener {
            //设置当前item 选中状态
            t.isCheck = checkBox!!.isChecked
            //通知全选按钮，及底部金额进行更新
            EventBus.getDefault().post("cart")
        }
        val imageView = holder?.getView<ImageView>(R.id.item_iv)
        imageView?.let { Glide.with(mContext).load(t?.goods_default_icon).into(it) }

    }
}